package fanshe;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import java_zhuoer_adv3.Student;

public class TestField {

	public static void main(String[] args) throws Exception {
		Class c = Student.class;
		Student st = (Student) c.newInstance();// 无参的构造方法
		System.out.println(st);
		Field[] fr = c.getDeclaredFields();
		System.out.println("Student类有哪些属性：");
		for (Field f : fr) {
			System.out.println(f);
		}
		Field fage = c.getDeclaredField("age");
		fage.setAccessible(true);
		fage.setInt(st, 30);
		Field fname = c.getDeclaredField("name");
		fname.setAccessible(true);
		fname.set(st, "尼古拉-赵四");
		System.out.println("修改后\n" + st);
		System.out.println(">>>>>>>>>>>>>列出所有的方法");

		Method mr[] = c.getDeclaredMethods();
		for (Method m : mr) {
			System.out.println(m);
		}
		Method msetId = c.getDeclaredMethod("setIDNumber", String.class);
		msetId.invoke(st, "合肥科海No-1");
		System.out.println(st);
		Method m2 = c.getDeclaredMethod("sayHi", String.class);
		m2.setAccessible(true);
		m2.invoke(st, "齐丹东");

		Method mage = c.getDeclaredMethod("getAge");
		Object rage = mage.invoke(st);
		System.out.println(rage);
	}
}
